from django.shortcuts import render

# Create your views here.
#
# 对于热销商品，前端在加载好页面后，向后端发送请求，获取属于当前商品类别（第三级类别）的热销商品。
#
# 后端接口设计：
#
# 请求方式 GET /goods/categories/(?P<category_id>\d+)/hotskus/


from rest_framework_extensions.cache.mixins import ListCacheResponseMixin
from rest_framework.generics import ListAPIView
from goods.models import SKU
from .serializers import SKUSerializer
# Create your views here.
class HotSKUListView(ListCacheResponseMixin,ListAPIView):
    """
    获取热销商品
    GET /goods/categories/(?P<category_id>\d+)/hotskus/
    """
    serializer_class = SKUSerializer
    pagination_class = None

    def get_queryset(self):
        category_id = self.kwargs['category_id']
        return SKU.objects.filter(category_id=category_id,is_launched=True).order_by('-sales')[:2]